package icasue.net.protocol.http;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/3/11 上午11:20
 * @UpdateDate:
 * @Description:
 */
public interface HttpOption {

    String getHeaderFormat();
    int getVersion();

    public enum V1_1 implements HttpOption{
        GET(11,"GET %s HTTP/1.1"),
        POST(12,"POST %s HTTP/1.1"),
        PUT(13,"PUT %s HTTP/1.1"),
        DELETE(14,"DELETE %s HTTP/1.1"),
        OPTION(15,"OPTION %s HTTP/1.1");
        public final String head;
        public final Integer version;
        V1_1(Integer version,String protocolHeader){
            this.head = protocolHeader;
            this.version = version;
        }

        public static HttpOption choose(String TYPE) {
            if(TYPE == null){
                return GET;
            }
            for (V1_1 option : values()) {
                if(option.name().equalsIgnoreCase(TYPE.trim())){
                    return option;
                }
            }
            return GET;
        }

        @Override
        public String getHeaderFormat() {
            return this.head;
        }

        @Override
        public int getVersion() {
            return this.version;
        }
    }

    public enum V2_0 implements HttpOption{
        GET(21,"GET %s HTTP/2.0"),
        POST(22,"POST %s HTTP/2.0"),
        PUT(23,"PUT %s HTTP/2.0"),
        DELETE(24,"DELETE %s HTTP/2.0"),
        OPTION(25,"OPTION %s HTTP/2.0");
        public final String head;
        public final Integer version;
        V2_0(Integer version,String protocolHeader){
            this.head = protocolHeader;
            this.version = version;
        }

        public static HttpOption choose(String TYPE) {
            if(TYPE == null){
                return GET;
            }
            for (V2_0 option : values()) {
                if(option.name().equalsIgnoreCase(TYPE.trim())){
                    return option;
                }
            }
            return GET;
        }

        @Override
        public String getHeaderFormat() {
            return this.head;
        }

        @Override
        public int getVersion() {
            return this.version;
        }
    }

}
